<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <title>添加仓库</title>
  <script type="text/javascript">
      Ext.onReady(function () {
          var companies = Ext.create('Ext.form.ComboBox', {
              fieldLabel: '所属公司',
              store: companyAllInfoStore,
              allowBlank: false,
              blankText: "公司必须选择",
              emptyText: '请选择...',
              valueField: 'id',
              displayField: 'name',
              name: 'company_id',
              loadingText: '搜索中...',
              minChars: 0,
              anchor: '100%',
              listConfig: {
                  loadingText: 'Searching...',
                  getInnerTpl: function () {
                      return '{name}';
                  }
              }
          });

          var number = Ext.create('Ext.form.field.Number', {
              fieldLabel: '编号',
              allowBlank: false,
              blankText: "编号不能为空",
              name: 'number',
              anchor: '100%'
          });

          var name = Ext.create('Ext.form.field.Text', {
              fieldLabel: '名称',
              allowBlank: false,
              blankText: "仓库名称不能为空",
              name: 'name',
              anchor: '100%'
          });


          var warehouseTypeStore = Ext.create('Ext.data.Store', {
              autoDestroy: true,
              autoSync: true,
              model: 'WarehouseType',
              proxy: {
                  type: 'ajax',
                  url: "/warehouse_type/getAllWarehouseTypes?for_cbb=true",
                  reader: {
                      type: 'json',
                      root: 'root',
                      totalProperty: 'totalProperty'// 数据集记录总数
                  }
              },
              pageSize: 1000,//default:25
              autoLoad: true
          });

          var warehouseType = Ext.create('Ext.form.ComboBox', {
              fieldLabel: '类型',
              store: warehouseTypeStore,
              allowBlank: false,
              typeAhead: true,
              valueField: 'id',
              displayField: 'name',
              name: 'warehouse_type_id',
              emptyText: '选择仓库类型...',
              //allowBlank: false,
              anchor: '100%'
          });

          var desc = Ext.create('Ext.form.TextArea', {
              fieldLabel: '描述',
              name: 'description',
              height: 80,
              anchor: '100%'
          });

          var newWarehouseForm = Ext.create('Ext.form.Panel', {
              fieldDefaults: {
                  labelWidth: 45,
                  labelAlign: 'right'
              },
              url: '/warehouse/create',
              frame: true,
              //title: '添加仓库',
              bodyStyle: 'padding:5px 5px 0',
              width: 290,
              height: 205,
              items: [companies,number, name, warehouseType, desc],
              buttons: [
                  {
                      text: '提交',
                      iconCls: 'icon-save',
                      handler: function () {
                          // check form value
                          if (newWarehouseForm.form.isValid()) {
                              newWarehouseForm.form.submit({
                                  method: 'GET',
                                  success: function (result, response) {
                                      if (response.result.info == "成功") {
                                          //添加成功后，隐藏窗口，并刷新Grid
                                          newWarehouseWin.destroy();
                                      }
                                      else {
                                          Ext.MessageBox.alert('消息', response.result.info);
                                      }
                                  },
                                  failure: function (result, response) {
                                      Ext.MessageBox.alert('提示', result.responseText);
                                  }
                              });
                          }
                          else {
                              Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                          }
                      }
                  },
                  {
                      text: '关闭',
                      iconCls: 'exit',
                      handler: function () {
                          newWarehouseForm.getForm().reset();
                          newWarehouseWin.destroy();
                      }
                  }
              ]
          });
          newWarehouseForm.render('new_warehouse_form');
      })
  </script>
</head>
<body>
<div id="new_warehouse_form"></div>
</body>
</html>
